//
//  ZRScanAreaView.m
//  ScreenRead
//
//  Created by 黄涛 on 2018/10/25.
//  Copyright © 2018年 アポロジャパン. All rights reserved.
//

#import "ZRScanAreaView.h"

@implementation ZRScanAreaView

- (void)drawRect:(CGRect)rect{
    [super drawRect:rect];

    UIBezierPath * rectPath = [UIBezierPath bezierPathWithRect:rect];
    rectPath.lineWidth = 1;
    rectPath.lineCapStyle = kCGLineCapRound;
    rectPath.lineJoinStyle = kCGLineCapRound;
    
    UIColor * rectColor = [UIColor greenColor];
    [rectColor set];
    
    [rectPath stroke];
    
    /** 正方形4角 */
    CGFloat lineW = 3;
    CGFloat lineL = 20;
    CGFloat rectW = rect.size.width;

    for (int i = 0; i < 4; i++) {

        CGFloat b_x = i % 2 == 0 ? lineW : rectW - lineW;
        CGFloat b_y = i < 2 ?   lineW : rectW - lineW;

        CGFloat a_x = b_x;
        CGFloat a_y = i < 2 ? lineL :  rectW - lineL;

        CGFloat c_x = i % 2 == 0 ?  lineL : rectW - lineL;
        CGFloat c_y = b_y;

        CGPoint a = CGPointMake(a_x, a_y);
        CGPoint b = CGPointMake(b_x, b_y);
        CGPoint c = CGPointMake(c_x, c_y);

        UIBezierPath * linePath = [UIBezierPath bezierPath];

        [linePath moveToPoint:a];
        [linePath addLineToPoint:b];
        [linePath addLineToPoint:c];

        linePath.lineWidth = lineW;

        rectPath.lineCapStyle = kCGLineCapRound;
        rectPath.lineJoinStyle = kCGLineCapRound;

        UIColor * rectColor = [UIColor greenColor];
        [rectColor set];

        [linePath stroke];
    }
}

@end
